﻿
''' <remarks>Logger Settings definitions</remarks>
Public Class ActivityLoggerConf
    Implements IConfig
    Private validationerror As String
    Public logfolder As String
    Public rotatelog As Boolean
    Public Shared ReadOnly LOGLEVEL_ERROR As String = "Error" 'on error
    Public Shared ReadOnly LOGLEVEL_INFO As String = "Info" 'simple information
    Public Shared ReadOnly LOGLEVEL_OPERATION As String = "Operation" 'operation




    Public Function loadConfig() As Boolean Implements IConfig.loadConfig
        logfolder = My.Settings.logdirectory
        If (String.IsNullOrEmpty(logfolder)) Then logfolder = My.Computer.FileSystem.SpecialDirectories.MyDocuments.ToString
        rotatelog = My.Settings.rotatelog
        Return True
    End Function

    Public Property validationerrors As String Implements IConfig.validationerrors
        Get
            Return validationerror
        End Get
        Set(ByVal value As String)
            validationerror = value
        End Set
    End Property

    Public Function checkConfig() As Boolean Implements IConfig.checkConfig
        If (String.IsNullOrEmpty(logfolder.Trim)) Then
            validationerrors = getEmptyForlderError()
            Return False
        End If
        If (Not System.IO.Directory.Exists(logfolder.Trim)) Then
            validationerrors = getNoexitingForlderError()
            Return False
        End If
        Return True
    End Function

    Public Function writeConfig() As Boolean Implements IConfig.writeConfig
        My.Settings.logdirectory = logfolder
        My.Settings.rotatelog = rotatelog
        Return True
    End Function

    Sub New()
        loadConfig()
    End Sub

    Private Function getEmptyForlderError() As String
        Dim cm As String = "Logs Directory cannot be empty." + vbCrLf + vbCrLf
        cm = cm + "Select"
        cm = cm + vbCrLf + vbTab + "- Cancel to revert the change or"
        cm = cm + vbCrLf + vbTab + "- No to correct input"
        cm = cm + vbCrLf + vbTab + "- Yes to continue. In this case, logs forlder will be set to My Documents folder"
        Return cm
    End Function
    Private Function getNoexitingForlderError() As String
        Dim cm As String = "the specified Logs Directory donnot exist" + vbCrLf
        cm = cm + "L"
        cm = cm + vbCrLf + vbTab + "- Cancel to revert the change or"
        cm = cm + vbCrLf + vbTab + "- No to correct input"
        cm = cm + vbCrLf + vbTab + "- Yes to continue. In this case, application may not function properly"
        Return cm
    End Function
End Class
